
package net.wujingchao.ohos.view;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.StackLayout;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.agp.utils.RectFloat;
import ohos.app.Context;

/**
 * Dark frame layout
 */
class DarkFrameLayout extends StackLayout implements Component.DrawTask {

    /**
     * * The constant MAX_ALPHA
     */
    public final static int MAX_ALPHA = 0x9f;

    /**
     * M fade paint
     */
    private Paint mFadePaint;

    /**
     * Alpha
     */
    private int alpha = 0x00;

    /**
     * M multi card menu
     */
    private MultiCardMenu mMultiCardMenu;

    /**
     * Dark frame layout
     *
     * @param context context
     */
    public DarkFrameLayout(Context context) {
        this(context, null);
    }

    /**
     * Dark frame layout
     *
     * @param context context
     * @param attrs   attrs
     */
    public DarkFrameLayout(Context context, AttrSet attrs) {
        this(context, attrs, null);
    }


    /**
     * Dark frame layout
     *
     * @param context      context
     * @param attrs        attrs
     * @param defStyleAttr def style attr
     */
    public DarkFrameLayout(Context context, AttrSet attrs, String defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mFadePaint = new Paint();
        addDrawTask(this);
    }

    /**
     * On draw *
     *
     * @param component component
     * @param canvas    canvas
     */
    @Override
    public void onDraw(Component component, Canvas canvas) {

        drawFade(canvas);

    }

    /**
     * Draw fade *
     *
     * @param canvas canvas
     */
    private void drawFade(Canvas canvas) {
        mFadePaint.setColor(new Color(Color.argb(alpha, 0, 0, 0)));
        canvas.drawRect(new RectFloat(0, 0, getWidth(), getHeight()), mFadePaint);
    }

    /**
     * Fade *
     *
     * @param fade fade
     */
    public void fade(boolean fade) {
        this.alpha = fade ? 0x00 : 0x00;
        invalidate();
    }

    /**
     * Fade *
     *
     * @param alpha alpha
     */
    public void fade(int alpha) {
        this.alpha = alpha;
        invalidate();
    }

    /**
     * Set multi card menu *
     *
     * @param multiCardMenu multi card menu
     */
    public void setMultiCardMenu(MultiCardMenu multiCardMenu) {
        this.mMultiCardMenu = multiCardMenu;
    }


}
